﻿@using Covenant.Models.Grunts
@model Grunt
@{
    IEnumerable<GruntTask> GruntTasks = ViewBag.GruntTasks;
}

<form id="task-submit-form" asp-controller="GruntTasking" asp-action="Create">
    <div asp-validation-summary="All" class="text-danger"></div>
    <input name="GruntId" value="@Model.Id" class="form-control" type="hidden" readonly>
    <div class="form-group col-md-4">
        <label for="set-task">Task</label>
        <select id="set-task" name="GruntTaskId" class="form-control">
            @foreach (var task in GruntTasks)
            {
                <option value="@task.Id">@task.Name</option>
            }
        </select>
    </div>
    @foreach (var task in GruntTasks)
    {
        <div class="d-none invisible @task.Name">
            @for (int i = 0; i < task.Options.Count; i++)
            {
                var fileinputs = new List<string> { "EncodedAssembly", "FileContents" };
                @if (!fileinputs.Contains(task.Options[i].Name))
                {
                    <div class="form-group col-md-12">
                        <label for="set-option-@task.Options[i].Name">@task.Options[i].Name</label>
                        <input id="set-option-@task.Options[i].Name" name="parameters[@i]" value="@task.Options[i].Value" class="form-control" disabled>
                    </div>
                }
                else
                {
                    <div class="form-group col-md-12">
                        <label for="set-option-@task.Options[i].Name">@task.Options[i].Name</label>
                        <input id="set-option-@task.Options[i].Name-filler" name="parameters[@i]" class="form-control file-filler" type="hidden" readonly disabled>
                        <input type="file" id="set-option-@task.Options[i].Name" class="form-control-file" disabled>
                    </div>
                }
            }
        </div>
    }
    <input name="Status" value="Uninitialized" class="form-control" type="hidden" readonly>
    <div class="form-group col-md-4">
        <button id="submit-task-button" type="button" class="btn btn-primary">Task</button>
    </div>
</form>